package geoip

const defaultCountryBasedAccuracy = 200

// FillMissingInfo tries to fill missing location information based on the
// available existing information.
func (l *Location) FillMissingInfo() {
	// Get coordinates from country.
	if l.Coordinates.Latitude == 0 &&
		l.Coordinates.Longitude == 0 &&
		l.Country.ISOCode != "" {
		if c, ok := countryCoordinates[l.Country.ISOCode]; ok {
			l.Coordinates = c
			l.Coordinates.AccuracyRadius = defaultCountryBasedAccuracy
		}
	}
}

var countryCoordinates = map[string]Coordinates{
	"AD": {Latitude: 42, Longitude: 1},
	"AE": {Latitude: 23, Longitude: 53},
	"AF": {Latitude: 33, Longitude: 67},
	"AG": {Latitude: 17, Longitude: -61},
	"AI": {Latitude: 18, Longitude: -63},
	"AL": {Latitude: 41, Longitude: 20},
	"AM": {Latitude: 40, Longitude: 45},
	"AN": {Latitude: 12, Longitude: -69},
	"AO": {Latitude: -11, Longitude: 17},
	"AQ": {Latitude: -75, Longitude: -0},
	"AR": {Latitude: -38, Longitude: -63},
	"AS": {Latitude: -14, Longitude: -170},
	"AT": {Latitude: 47, Longitude: 14},
	"AU": {Latitude: -25, Longitude: 133},
	"AW": {Latitude: 12, Longitude: -69},
	"AZ": {Latitude: 40, Longitude: 47},
	"BA": {Latitude: 43, Longitude: 17},
	"BB": {Latitude: 13, Longitude: -59},
	"BD": {Latitude: 23, Longitude: 90},
	"BE": {Latitude: 50, Longitude: 4},
	"BF": {Latitude: 12, Longitude: -1},
	"BG": {Latitude: 42, Longitude: 25},
	"BH": {Latitude: 25, Longitude: 50},
	"BI": {Latitude: -3, Longitude: 29},
	"BJ": {Latitude: 9, Longitude: 2},
	"BM": {Latitude: 32, Longitude: -64},
	"BN": {Latitude: 4, Longitude: 114},
	"BO": {Latitude: -16, Longitude: -63},
	"BR": {Latitude: -14, Longitude: -51},
	"BS": {Latitude: 25, Longitude: -77},
	"BT": {Latitude: 27, Longitude: 90},
	"BV": {Latitude: -54, Longitude: 3},
	"BW": {Latitude: -22, Longitude: 24},
	"BY": {Latitude: 53, Longitude: 27},
	"BZ": {Latitude: 17, Longitude: -88},
	"CA": {Latitude: 56, Longitude: -106},
	"CC": {Latitude: -12, Longitude: 96},
	"CD": {Latitude: -4, Longitude: 21},
	"CF": {Latitude: 6, Longitude: 20},
	"CG": {Latitude: -0, Longitude: 15},
	"CH": {Latitude: 46, Longitude: 8},
	"CI": {Latitude: 7, Longitude: -5},
	"CK": {Latitude: -21, Longitude: -159},
	"CL": {Latitude: -35, Longitude: -71},
	"CM": {Latitude: 7, Longitude: 12},
	"CN": {Latitude: 35, Longitude: 104},
	"CO": {Latitude: 4, Longitude: -74},
	"CR": {Latitude: 9, Longitude: -83},
	"CU": {Latitude: 21, Longitude: -77},
	"CV": {Latitude: 16, Longitude: -24},
	"CX": {Latitude: -10, Longitude: 105},
	"CY": {Latitude: 35, Longitude: 33},
	"CZ": {Latitude: 49, Longitude: 15},
	"DE": {Latitude: 51, Longitude: 10},
	"DJ": {Latitude: 11, Longitude: 42},
	"DK": {Latitude: 56, Longitude: 9},
	"DM": {Latitude: 15, Longitude: -61},
	"DO": {Latitude: 18, Longitude: -70},
	"DZ": {Latitude: 28, Longitude: 1},
	"EC": {Latitude: -1, Longitude: -78},
	"EE": {Latitude: 58, Longitude: 25},
	"EG": {Latitude: 26, Longitude: 30},
	"EH": {Latitude: 24, Longitude: -12},
	"ER": {Latitude: 15, Longitude: 39},
	"ES": {Latitude: 40, Longitude: -3},
	"ET": {Latitude: 9, Longitude: 40},
	"FI": {Latitude: 61, Longitude: 25},
	"FJ": {Latitude: -16, Longitude: 179},
	"FK": {Latitude: -51, Longitude: -59},
	"FM": {Latitude: 7, Longitude: 150},
	"FO": {Latitude: 61, Longitude: -6},
	"FR": {Latitude: 46, Longitude: 2},
	"GA": {Latitude: -0, Longitude: 11},
	"GB": {Latitude: 55, Longitude: -3},
	"GD": {Latitude: 12, Longitude: -61},
	"GE": {Latitude: 42, Longitude: 43},
	"GF": {Latitude: 3, Longitude: -53},
	"GG": {Latitude: 49, Longitude: -2},
	"GH": {Latitude: 7, Longitude: -1},
	"GI": {Latitude: 36, Longitude: -5},
	"GL": {Latitude: 71, Longitude: -42},
	"GM": {Latitude: 13, Longitude: -15},
	"GN": {Latitude: 9, Longitude: -9},
	"GP": {Latitude: 16, Longitude: -62},
	"GQ": {Latitude: 1, Longitude: 10},
	"GR": {Latitude: 39, Longitude: 21},
	"GS": {Latitude: -54, Longitude: -36},
	"GT": {Latitude: 15, Longitude: -90},
	"GU": {Latitude: 13, Longitude: 144},
	"GW": {Latitude: 11, Longitude: -15},
	"GY": {Latitude: 4, Longitude: -58},
	"GZ": {Latitude: 31, Longitude: 34},
	"HK": {Latitude: 22, Longitude: 114},
	"HM": {Latitude: -53, Longitude: 73},
	"HN": {Latitude: 15, Longitude: -86},
	"HR": {Latitude: 45, Longitude: 15},
	"HT": {Latitude: 18, Longitude: -72},
	"HU": {Latitude: 47, Longitude: 19},
	"ID": {Latitude: -0, Longitude: 113},
	"IE": {Latitude: 53, Longitude: -8},
	"IL": {Latitude: 31, Longitude: 34},
	"IM": {Latitude: 54, Longitude: -4},
	"IN": {Latitude: 20, Longitude: 78},
	"IO": {Latitude: -6, Longitude: 71},
	"IQ": {Latitude: 33, Longitude: 43},
	"IR": {Latitude: 32, Longitude: 53},
	"IS": {Latitude: 64, Longitude: -19},
	"IT": {Latitude: 41, Longitude: 12},
	"JE": {Latitude: 49, Longitude: -2},
	"JM": {Latitude: 18, Longitude: -77},
	"JO": {Latitude: 30, Longitude: 36},
	"JP": {Latitude: 36, Longitude: 138},
	"KE": {Latitude: -0, Longitude: 37},
	"KG": {Latitude: 41, Longitude: 74},
	"KH": {Latitude: 12, Longitude: 104},
	"KI": {Latitude: -3, Longitude: -168},
	"KM": {Latitude: -11, Longitude: 43},
	"KN": {Latitude: 17, Longitude: -62},
	"KP": {Latitude: 40, Longitude: 127},
	"KR": {Latitude: 35, Longitude: 127},
	"KW": {Latitude: 29, Longitude: 47},
	"KY": {Latitude: 19, Longitude: -80},
	"KZ": {Latitude: 48, Longitude: 66},
	"LA": {Latitude: 19, Longitude: 102},
	"LB": {Latitude: 33, Longitude: 35},
	"LC": {Latitude: 13, Longitude: -60},
	"LI": {Latitude: 47, Longitude: 9},
	"LK": {Latitude: 7, Longitude: 80},
	"LR": {Latitude: 6, Longitude: -9},
	"LS": {Latitude: -29, Longitude: 28},
	"LT": {Latitude: 55, Longitude: 23},
	"LU": {Latitude: 49, Longitude: 6},
	"LV": {Latitude: 56, Longitude: 24},
	"LY": {Latitude: 26, Longitude: 17},
	"MA": {Latitude: 31, Longitude: -7},
	"MC": {Latitude: 43, Longitude: 7},
	"MD": {Latitude: 47, Longitude: 28},
	"ME": {Latitude: 42, Longitude: 19},
	"MG": {Latitude: -18, Longitude: 46},
	"MH": {Latitude: 7, Longitude: 171},
	"MK": {Latitude: 41, Longitude: 21},
	"ML": {Latitude: 17, Longitude: -3},
	"MM": {Latitude: 21, Longitude: 95},
	"MN": {Latitude: 46, Longitude: 103},
	"MO": {Latitude: 22, Longitude: 113},
	"MP": {Latitude: 17, Longitude: 145},
	"MQ": {Latitude: 14, Longitude: -61},
	"MR": {Latitude: 21, Longitude: -10},
	"MS": {Latitude: 16, Longitude: -62},
	"MT": {Latitude: 35, Longitude: 14},
	"MU": {Latitude: -20, Longitude: 57},
	"MV": {Latitude: 3, Longitude: 73},
	"MW": {Latitude: -13, Longitude: 34},
	"MX": {Latitude: 23, Longitude: -102},
	"MY": {Latitude: 4, Longitude: 101},
	"MZ": {Latitude: -18, Longitude: 35},
	"NA": {Latitude: -22, Longitude: 18},
	"NC": {Latitude: -20, Longitude: 165},
	"NE": {Latitude: 17, Longitude: 8},
	"NF": {Latitude: -29, Longitude: 167},
	"NG": {Latitude: 9, Longitude: 8},
	"NI": {Latitude: 12, Longitude: -85},
	"NL": {Latitude: 52, Longitude: 5},
	"NO": {Latitude: 60, Longitude: 8},
	"NP": {Latitude: 28, Longitude: 84},
	"NR": {Latitude: -0, Longitude: 166},
	"NU": {Latitude: -19, Longitude: -169},
	"NZ": {Latitude: -40, Longitude: 174},
	"OM": {Latitude: 21, Longitude: 55},
	"PA": {Latitude: 8, Longitude: -80},
	"PE": {Latitude: -9, Longitude: -75},
	"PF": {Latitude: -17, Longitude: -149},
	"PG": {Latitude: -6, Longitude: 143},
	"PH": {Latitude: 12, Longitude: 121},
	"PK": {Latitude: 30, Longitude: 69},
	"PL": {Latitude: 51, Longitude: 19},
	"PM": {Latitude: 46, Longitude: -56},
	"PN": {Latitude: -24, Longitude: -127},
	"PR": {Latitude: 18, Longitude: -66},
	"PS": {Latitude: 31, Longitude: 35},
	"PT": {Latitude: 39, Longitude: -8},
	"PW": {Latitude: 7, Longitude: 134},
	"PY": {Latitude: -23, Longitude: -58},
	"QA": {Latitude: 25, Longitude: 51},
	"RE": {Latitude: -21, Longitude: 55},
	"RO": {Latitude: 45, Longitude: 24},
	"RS": {Latitude: 44, Longitude: 21},
	"RU": {Latitude: 61, Longitude: 105},
	"RW": {Latitude: -1, Longitude: 29},
	"SA": {Latitude: 23, Longitude: 45},
	"SB": {Latitude: -9, Longitude: 160},
	"SC": {Latitude: -4, Longitude: 55},
	"SD": {Latitude: 12, Longitude: 30},
	"SE": {Latitude: 60, Longitude: 18},
	"SG": {Latitude: 1, Longitude: 103},
	"SH": {Latitude: -24, Longitude: -10},
	"SI": {Latitude: 46, Longitude: 14},
	"SJ": {Latitude: 77, Longitude: 23},
	"SK": {Latitude: 48, Longitude: 19},
	"SL": {Latitude: 8, Longitude: -11},
	"SM": {Latitude: 43, Longitude: 12},
	"SN": {Latitude: 14, Longitude: -14},
	"SO": {Latitude: 5, Longitude: 46},
	"SR": {Latitude: 3, Longitude: -56},
	"ST": {Latitude: 0, Longitude: 6},
	"SV": {Latitude: 13, Longitude: -88},
	"SY": {Latitude: 34, Longitude: 38},
	"SZ": {Latitude: -26, Longitude: 31},
	"TC": {Latitude: 21, Longitude: -71},
	"TD": {Latitude: 15, Longitude: 18},
	"TF": {Latitude: -49, Longitude: 69},
	"TG": {Latitude: 8, Longitude: 0},
	"TH": {Latitude: 15, Longitude: 100},
	"TJ": {Latitude: 38, Longitude: 71},
	"TK": {Latitude: -8, Longitude: -171},
	"TL": {Latitude: -8, Longitude: 125},
	"TM": {Latitude: 38, Longitude: 59},
	"TN": {Latitude: 33, Longitude: 9},
	"TO": {Latitude: -21, Longitude: -175},
	"TR": {Latitude: 38, Longitude: 35},
	"TT": {Latitude: 10, Longitude: -61},
	"TV": {Latitude: -7, Longitude: 177},
	"TW": {Latitude: 23, Longitude: 120},
	"TZ": {Latitude: -6, Longitude: 34},
	"UA": {Latitude: 48, Longitude: 31},
	"UG": {Latitude: 1, Longitude: 32},
	"US": {Latitude: 37, Longitude: -95},
	"UY": {Latitude: -32, Longitude: -55},
	"UZ": {Latitude: 41, Longitude: 64},
	"VA": {Latitude: 41, Longitude: 12},
	"VC": {Latitude: 12, Longitude: -61},
	"VE": {Latitude: 6, Longitude: -66},
	"VG": {Latitude: 18, Longitude: -64},
	"VI": {Latitude: 18, Longitude: -64},
	"VN": {Latitude: 14, Longitude: 108},
	"VU": {Latitude: -15, Longitude: 166},
	"WF": {Latitude: -13, Longitude: -177},
	"WS": {Latitude: -13, Longitude: -172},
	"XK": {Latitude: 42, Longitude: 20},
	"YE": {Latitude: 15, Longitude: 48},
	"YT": {Latitude: -12, Longitude: 45},
	"ZA": {Latitude: -30, Longitude: 22},
	"ZM": {Latitude: -13, Longitude: 27},
	"ZW": {Latitude: -19, Longitude: 29},
}
